<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>系统登录</title>
    <link rel="stylesheet" href="../../../backstage/css/login.css">
    <script type="text/javascript" src="../../../backstage/js/jquery.min.js"></script>
    <script src="../../../backstage/lib/layui/layui.js" charset="utf-8"></script>
</head>

<body class="login-bg">
<div class="login">
    <div class="message">系统登录</div>
    <hr class="hr20">
    <form method="post" class="layui-form">
        <input id="username" placeholder="用户名" autocomplete="off" type="text" lay-verify="required" class="layui-input">
        <div id="username1" style="color: #FD3F31;display: none;">用户名不能为空</div>
        <hr class="hr15">
        <input id="password" placeholder="密码" autocomplete="off" type="password" lay-verify="required" class="layui-input">
        <div id="pwd1" style="color: #FD3F31;display: none;">密码不能为空</div>
        <hr class="hr15">
        <input value="登录" id="login-btn" lay-submit lay-filter="login" style="width:100%;margin-top: 5%;" type="button">
        <hr class="hr20">
    </form>
</div>

<script>
    $(function() {
        //失去焦点时，用户名不能为空
        $("#username").blur(function(){
            var uname = $.trim($("#username").val());
            if(uname.length <= 0) {
                $("#username1").toggle();
            } else {
                $("#username1").hide();
            }
        });

        //失去焦点时，密码不能为空
        $("#password").blur(function(){
            var pwd = $.trim($("#password").val());
            if(pwd.length <= 0) {
                $("#pwd1").toggle();
            } else {
                $("#pwd1").hide();
            }
        });

        //管理员登录
        $("#login-btn").click(function() {
            var username = $.trim($("#username").val());
            var pwd = $.trim($("#password").val());
            $.ajax({
                type: 'POST',
                url: '/user/loginManager',
                dataType: "json",
                data: {username: username, pwd: pwd},
                error: function () {
                    alert("失败");
                },
                success: function (result) {
                    if(result.msg=="欢迎登陆管理后台！"){
                        //alert('登录成功！');
                        window.location.href = '${path}/homeAdmin';
                    } else if(result.msg=="该用户不存在！"){
                        alert('该用户不存在！');
                    } else if(result.msg=="用户名或密码不正确") {
                        alert('用户名或密码不正确');
                    } else if(result.msg=="用户名或密码不能为空！") {
                        alert('用户名或密码不能为空！');
                    }
                }
            });
        });
    });
</script>
</body>

</html>